package org.wak.utils
{
	public class Utils
	{
		
		public function Utils()
		{
		}
		
		/**
		 * Calculate the angle between two differents points.
		 * @param pX1: X coordinate of the first point.
		 * @param pY1: Y coordinate of the first point.
		 * @param pX2: X coordinate of the second point.
		 * @param pY2: Y coordinate of the second point.
		 * 
		 * @return The angle between the two points in radians.
		 */ 
		public static function AngleInTwoPointsP( pX1:Number, pY1:Number, pX2:Number, pY2:Number):Number
		{
			 
		
			
			var fDeltaX:Number = pX2 - pX1;
			var fDeltaY:Number = pY2 - pY1;
			
			var x2:Number = 1 ;
			var y2:Number = 0 ;
		
			var ret_angle:Number ;
		
			var partNumerador:Number ;
			var partDenominador:Number ;
		
			partNumerador = (fDeltaX * x2) + (fDeltaY * y2) ;
		
			partDenominador = Math.sqrt( (fDeltaX * fDeltaX) + (fDeltaY * fDeltaY) ) * Math.sqrt( (x2 * x2) + (y2 * y2) ) ;
		
			ret_angle = Math.acos( partNumerador / partDenominador );
		
			if( ((fDeltaX <= 0) && (fDeltaY < 0 )) || ( (fDeltaX >= 0) && (fDeltaY < 0 ) ) )
			{
				ret_angle = (Math.PI * 2) - ret_angle ;
			}
		
			return ret_angle ;
			
		}
		
		/**
		 * Converts radians angle value to degrees.
		 * 
		 * @param pRad angle in radians to be converted.
		 * 
		 * @return The angle converted to degrees.
		 * 
		 * @see ToRad
		 */		
		public static function ToDeg(pRad:Number):Number
		{
			var fRetDeg:Number = (pRad * 180) / Math.PI ;
			return fRetDeg ;
			
		}
		
		/**
		 * Converts degrees angle value to radians.
		 * 
		 * @param pDeg angle in degrees to be converted.
		 * 
		 * @return The angle converted to radians.
		 * 
		 * @see ToDeg
		 */		
		public static function ToRad(pDeg:Number):Number
		{
			var fRetRad:Number = (pDeg * Math.PI) / 180.0 ;
			return fRetRad ;
			
		}
		
		/**
		 * Check if the value stored <code>pVal</code> is between the values
		 * stored in <code>pA</code> and <code>pB</code>
		 * 
		 * @param pVal the value to be tested.
		 * @param pA the min value of the range.
		 * @param pB the max value of the range.
		 * 
		 * @return true if <code>pVal</code> is between <code>pA</code> and <code>pB</code> else false.
		 * 
		 */	
		public static function IsBetween(pVal:Number, pA:Number, pB:Number ):Boolean
		{
			if( (pVal > pA) && (pVal < pB) )
			{
				return true ;				
			}
			else
			{
				return false ;
			}
		}
		
		/**
		 * Align a coordinate to be in the center 
		 * @param pW1 Width of the contained object
		 * @param pWContainer width of the container
		 * @return the coordinate value to be in the center.
		 * 
		 */		
		public static function AlignCenter( pW1:Number, pWContainer:Number ):Number
		{
			var fRetX:Number = 0 ;
			
			fRetX = (pWContainer / 2) - (pW1/2) ;
			
			return fRetX ;
		}

	}
}